package com.ttc.mBackupK16.BackupContacts;

import com.ttc.mBackupK16.R;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class ContactsListActivity extends Activity implements OnClickListener{

	private Cursor mCursor;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.contacts_list);
		
		Button btnBackupContacts, btnCancelContacts;
		CheckBox chBCheckAllContacts;
		ListView lstContacts;
		
		btnBackupContacts = (Button)findViewById(R.id.btnBackupContacts);
		btnCancelContacts = (Button)findViewById(R.id.btnCancelContacts);
		chBCheckAllContacts = (CheckBox)findViewById(R.id.chBCheckAllContacts);
		lstContacts = (ListView)findViewById(R.id.lstContacts);
		
		btnBackupContacts.setOnClickListener(this);
		btnCancelContacts.setOnClickListener(this);
		chBCheckAllContacts.setOnClickListener(this);
		//lstContacts.setOnClickListener(this);
		
		 mCursor = this.getContentResolver().query(ContactsContract.Data.CONTENT_URI, 
	        		new String[]{ContactsContract.Contacts._ID, 
	        		ContactsContract.Contacts.DISPLAY_NAME, Phone.NUMBER },
	        		Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", 
	        		null, null);
	        
	        ListAdapter adapter1 = new SimpleCursorAdapter(this, R.layout.contact_row, mCursor, 
	        		new String[]{ContactsContract.Contacts.DISPLAY_NAME}, 
	        		new int[]{R.id.txtContactRowName});
	        lstContacts.setAdapter(adapter1);
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btnBackupContacts:
			
			break;
		case R.id.btnCancelContacts:
			this.finish();
			break;
		case R.id.chBCheckAllContacts:
			Toast.makeText(getBaseContext(), "CheckAll Contacts clicked!", Toast.LENGTH_SHORT).show();
			break;

		default:
			break;
		}
	}
}
